package com.gzzhcm.czh.myceshi;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.gzzhcm.czh.myceshi.fragemnt.Fragment2;
import com.gzzhcm.czh.myceshi.fragemnt.Fragment3;
import com.gzzhcm.czh.myceshi.fragemnt.Fragment4;
import com.gzzhcm.czh.myceshi.fragemnt.Fragment5;
import com.gzzhcm.czh.myceshi.fragemnt.ShoyeFragment;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.activity_fragment)
public class FragmentActivity extends AppCompatActivity implements View.OnClickListener{
    @ViewInject(R.id.tv_home_xxzx)
    private TextView tvxxzx;
    @ViewInject(R.id.tv_home_bbn)
    private TextView tvbbn;
    @ViewInject(R.id.tv_home_grzx)
    private TextView tvgrzx;
    @ViewInject(R.id.tv_home_wyk)
    private TextView tvwyk;
    @ViewInject(R.id.img_home_fb)
    private ImageView imfb;
    @ViewInject(R.id.frame_content)
    private FrameLayout fragmentq;
    @ViewInject(R.id.img_home_xxzx)
    private ImageView imgXxzx;
    @ViewInject(R.id.img_home_bbn)
    private ImageView imgBbn;
    @ViewInject(R.id.img_home_wyk)
    private ImageView imgWyk;
    @ViewInject(R.id.img_home_grzx)
    private ImageView imgGrzx;
    private ShoyeFragment xxzxFragment;
    private Fragment2 bbnFragment;
    private Fragment3 wykFragment;
    private Fragment4 wdFragment;
    private Fragment5 fbFragment;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        intView();
    }

    private void intView() {
        tvxxzx.setOnClickListener(this);
        tvbbn.setOnClickListener(this);
        tvwyk.setOnClickListener(this);
        tvgrzx.setOnClickListener(this);
        imfb.setOnClickListener(this);
        imgXxzx.setOnClickListener(this);
        imgBbn.setOnClickListener(this);
        imgWyk.setOnClickListener(this);
        imgGrzx.setOnClickListener(this);
        xxzxF();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_home_xxzx:
                clearSelection();
                xxzxF();
                break;
            case R.id.tv_home_bbn:
//                 帮帮你

                clearSelection();
                bbnF();


                break;
            case R.id.tv_home_wyk:
//                我有空

                clearSelection();
                wykF();


            case R.id.tv_home_grzx:
//
                clearSelection();
                grzxF();

                break;
            case R.id.img_home_fb:
//                发布
//                clearSelection();
//                fbF();
                break;
        }
    }
    private void wykF() {
        // 实例化Fragment页面
        wykFragment = new Fragment3();
        // 得到Fragment事务管理器
        FragmentTransaction fragmentTransaction = this
                .getSupportFragmentManager().beginTransaction();
        // 替换当前的页面
        fragmentTransaction.replace(R.id.frame_content, wykFragment);
        // 事务管理提交
        fragmentTransaction.commit();
//        atIv.setImageResource(R.drawable.message);
        tvwyk.setTextColor(Color.parseColor("#009944"));
        imgWyk.setImageResource(R.drawable.yuoko1);

        // 改变选中状态
        tvxxzx.setSelected(false);
        imgXxzx.setSelected(false);
        tvbbn.setSelected(false);
        imgBbn.setSelected(false);
        tvwyk.setSelected(true);
        imgWyk.setSelected(true);
        tvgrzx.setSelected(false);
        imgGrzx.setSelected(false);
        imfb.setSelected(false);
    }
    private void grzxF() {
        // 实例化Fragment页面
        wdFragment = new Fragment4();
        // 得到Fragment事务管理器
        FragmentTransaction fragmentTransaction = this
                .getSupportFragmentManager().beginTransaction();
        // 替换当前的页面
        fragmentTransaction.replace(R.id.frame_content, wdFragment);
        // 事务管理提交
        fragmentTransaction.commit();
//        atIv.setImageResource(R.drawable.message);
        tvgrzx.setTextColor(Color.parseColor("#009944"));
        imgGrzx.setImageResource(R.drawable.wode1);

        // 改变选中状态
        // 改变选中状态
        tvxxzx.setSelected(false);
        imgXxzx.setSelected(false);
        tvbbn.setSelected(false);
        imgBbn.setSelected(false);
        tvwyk.setSelected(false);
        imgWyk.setSelected(false);
        tvgrzx.setSelected(true);
        imgGrzx.setSelected(true);
        imfb.setSelected(false);
    }
    private void xxzxF() {
        // 实例化Fragment页面
        xxzxFragment = new ShoyeFragment();
        // 得到Fragment事务管理器
        FragmentTransaction fragmentTransaction = this
                .getSupportFragmentManager().beginTransaction();
        // 替换当前的页面
        fragmentTransaction.replace(R.id.frame_content, xxzxFragment);
        // 事务管理提交
        fragmentTransaction.commit();
//        atIv.setImageResource(R.drawable.message);
        tvxxzx.setTextColor(Color.parseColor("#009944"));
        imgXxzx.setImageResource(R.drawable.shoye1);

        // 改变选中状态
        tvxxzx.setSelected(true);
        imgXxzx.setSelected(true);
        tvbbn.setSelected(false);
        imgBbn.setSelected(false);
        tvwyk.setSelected(false);
        imgWyk.setSelected(false);
        tvgrzx.setSelected(false);
        imgGrzx.setSelected(false);
        imfb.setSelected(false);
    }

    private void bbnF() {
        // 实例化Fragment页面
        bbnFragment = new Fragment2();
        // 得到Fragment事务管理器
        FragmentTransaction fragmentTransaction = this
                .getSupportFragmentManager().beginTransaction();
        // 替换当前的页面
        fragmentTransaction.replace(R.id.frame_content, bbnFragment);
        // 事务管理提交
        fragmentTransaction.commit();
//        atIv.setImageResource(R.drawable.message);
        tvbbn.setTextColor(Color.parseColor("#009944"));
        imgBbn.setImageResource(R.drawable.bang1);

        // 改变选中状态
        tvxxzx.setSelected(false);
        imgXxzx.setSelected(false);
        tvbbn.setSelected(true);
        imgBbn.setSelected(true);
        tvwyk.setSelected(false);
        imgWyk.setSelected(false);
        tvgrzx.setSelected(false);
        imgGrzx.setSelected(false);
        imfb.setSelected(false);
    }
    private void clearSelection() {
        tvxxzx .setTextColor(Color.parseColor("#666666"));
        tvbbn.setTextColor(Color.parseColor("#666666"));
        tvwyk.setTextColor(Color.parseColor("#666666"));
        tvgrzx.setTextColor(Color.parseColor("#666666"));
        imgXxzx.setImageResource(R.drawable.shoye);
        imgBbn.setImageResource(R.drawable.bang);
        imgWyk.setImageResource(R.drawable.yuoko);
        imgGrzx.setImageResource(R.drawable.wode);
        imfb.setImageResource(R.drawable.fabu);
    }

//    public  void showPopMenu() {
//        View view = View.inflate(this, R.layout.share_popup_menu, null);
//        bt_qx = view.findViewById(R.id.bt_fb_qx);
//        imgWj = view.findViewById(R.id.img_fabu_wj);
//        imgWyksp = view.findViewById(R.id.img_fabu_wyk);
//        imgRll = view.findViewById(R.id.img_fabu_rll);
//        imgJgdc = view.findViewById(R.id.img_fabu_jgdc);
//        imgSk = view.findViewById(R.id.img_fabu_sk);
//        imgSjzq = view.findViewById(R.id.img_fabu_sjzq);
//        imgSos = view.findViewById(R.id.img_fabu_sos);
//
//
//        bt_qx.setOnClickListener(this);
//        imgWj.setOnClickListener(this);
//        imgWyksp.setOnClickListener(this);
//        imgRll.setOnClickListener(this);
//        imgJgdc.setOnClickListener(this);
//        imgSjzq.setOnClickListener(this);
//        imgSk.setOnClickListener(this);
//        imgSos.setOnClickListener(this);
//        view.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                mpopupWindow.dismiss();
//            }
//        });
//        view.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in));
//        LinearLayout ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup);
//        ll_popup.startAnimation(AnimationUtils.loadAnimation(this, R.anim.push_bottom_in));
//        if(mpopupWindow==null){
//            mpopupWindow = new PopupWindow(this);
//            mpopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
//            mpopupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
//            mpopupWindow.setBackgroundDrawable(new BitmapDrawable());
//
//            mpopupWindow.setFocusable(true);
//            mpopupWindow.setOutsideTouchable(true);
//        }
//
//        mpopupWindow.setContentView(view);
//        mpopupWindow.showAtLocation(imfb, Gravity.BOTTOM, 0, 0);
//        mpopupWindow.update();
//    }
}
